# encoding: utf-8
import os

from datetime import datetime
from google.appengine.api import memcache
from google.appengine.ext import db

import models
import memcache_def

def wgw_init():
	# 初始化网站设置参数
	add_setting('site_name','wanglei website','website name','string')
	add_setting('count_rec_comments','5','count recent comments','int')
	add_setting('count_per_page','5','count per pages','int')
	add_setting('count_per_root','5','count per root page','int')
	add_setting('site_url','http://weblog-wanglei.appspot.com/','site url','string')
	add_setting('comment_per_page','8','comment_per_page','int')

def init_page():
	# 初始化页面
	add_page('about','this is init about')

def add_setting(v_name,v_value,v_miaoshu,v_type):
	new_setting = models.Setting(name=v_name,value=v_value,miaoshu=v_miaoshu,type=v_type)
	new_setting.put()

def add_page(title,content):
	month_year = datetime.strftime(datetime.now(),'%m_%Y')
	new_page = models.Article(title=title, content=content, month_year=month_year, article_type='page')
	new_page.put()

def wgw_change_setting(settings):
	zidian_settings = {}
	for setting in settings:
		if setting.type == 'int':
			zidian_settings[setting.name] = int(setting.value)
		else:
			zidian_settings[setting.name] = setting.value
	return zidian_settings
